package com.xqzgj.stock.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xqzgj.common.annotation.Log;
import com.xqzgj.common.core.controller.BaseController;
import com.xqzgj.common.core.domain.AjaxResult;
import com.xqzgj.common.enums.BusinessType;
import com.xqzgj.stock.domain.LogType;
import com.xqzgj.stock.service.ILogTypeService;
import com.xqzgj.common.utils.poi.ExcelUtil;
import com.xqzgj.common.core.page.TableDataInfo;

/**
 * 库存变动类型Controller
 * 
 * @author zhoujiam
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/stock/log/type")
public class LogTypeController extends BaseController {
    @Autowired
    private ILogTypeService logTypeService;

    /**
     * 查询库存变动类型列表
     */
    @PreAuthorize("@ss.hasPermi('stock:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(LogType logType) {
        startPage();
        List<LogType> list = logTypeService.selectLogTypeList(logType);
        return getDataTable(list);
    }

    /**
     * 导出库存变动类型列表
     */
    @PreAuthorize("@ss.hasPermi('stock:type:export')")
    @Log(title = "库存变动类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogType logType) {
        List<LogType> list = logTypeService.selectLogTypeList(logType);
        ExcelUtil<LogType> util = new ExcelUtil<LogType>(LogType.class);
        util.exportExcel(response, list, "库存变动类型数据");
    }

    /**
     * 获取库存变动类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId) {
        return success(logTypeService.selectLogTypeById(typeId));
    }

    /**
     * 新增库存变动类型
     */
    @PreAuthorize("@ss.hasPermi('stock:type:add')")
    @Log(title = "库存变动类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogType logType) {
        return toAjax(logTypeService.insertLogType(logType));
    }

    /**
     * 修改库存变动类型
     */
    @PreAuthorize("@ss.hasPermi('stock:type:edit')")
    @Log(title = "库存变动类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogType logType) {
        return toAjax(logTypeService.updateLogType(logType));
    }

    /**
     * 删除库存变动类型
     */
    @PreAuthorize("@ss.hasPermi('stock:type:remove')")
    @Log(title = "库存变动类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return toAjax(logTypeService.deleteLogTypeByIds(typeIds));
    }
}